package com.ccnf.controller;

import com.ccnf.core.bean.ResponseWithData;
import com.ccnf.model.ao.PassToken;
import com.ccnf.service.SaasService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 * 微信相关API 前端控制器
 * </p>
 *
 * @author developer
 * @since 2018-10-09
 */
@Controller
@RequestMapping("/v1/wx")
@Api(value = "WXController", description = "微信相关API")
public class WXController extends BaseController {
    @Autowired
    private SaasService saasService;
    @Autowired
    private HttpServletRequest request;

    @PassToken
    @GetMapping("entry")
    public String saasEntry(HttpServletRequest request) {
        return "redirect:" + saasService.saasLoginUrl(request);
    }

    @PassToken
    @GetMapping("callback")
    public String saasReturn(@RequestParam Map<String, String> requestParams) {
        return "redirect:" + saasService.handleSaasLoignReturn(requestParams);
    }

    @ResponseBody
    @ApiOperation("获取会管家微信分享jssdk")
    @GetMapping("jssdk")
    public ResponseWithData wxJsSdk(String currentUrl) {
        return ResponseWithData.success(saasService.saasShareConfig(getTokenParams(), currentUrl));
    }

    @ResponseBody
    @ApiOperation("获取会管家微信分享jssdk")
    @GetMapping("share/entry")
    public ResponseWithData shareEntry(String currentUrl) {
        Map<String, Object> data = saasService.shareEntry(request, getTokenParams(), currentUrl);
        return ResponseWithData.success(data);
    }

    @ResponseBody
    @ApiOperation("获取腾讯云配置")
    @GetMapping("tx/config")
    public ResponseWithData txConfig() {
        return ResponseWithData.success(saasService.getTxCosConfig());
    }
}